home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 1.3 KB | 49 lines | [TEXT/GEOL] |
- Item 9958881 21-Aug-90 19:16PDT
-
- From: D3431 MacroMind Programmers,PRT
-
- To: CPLUS.DEV$ C++ Interest List--Developers
- CPLUS.APPLE$ C++ Interest List--Apple Employees
-
- Sub: C++ enum translation riddle
-
- Can anyone answer this code generation riddle?
-
- Given this in C++:
-
- typedef enum {
- apple = 35, orange, banana
- } fruit;
-
- void func()
- {
- fruit a = apple;
- }
-
- Why C code generated is [equivalent to] this?
-
- enum fruit{apple, orange, banana};
-
- typedef unsigned char fruit;
-
- void func()
- {
- unsigned char a = ((unsigned char )35);
- }
-
-
- An incorrect enum for fruit is generated (note apple == 0), but that's OK,
- since it never passes the enums through to the C compiler! A type is generated
- for fruit, but it is never used?
-
- I could understand if all mention of enums vanished, and CFront preprocessed
- them into ints (making them conform to C++ and Ansi enums). I could understand
- if enums were simply passed through to the C compiler (allowing enums to be
- size optimized as they by MPW C). I just don't understand the explicit
- optimization in output plus spurius (and incorrect) type declarations!
-
- Haim Zamir
- MacroMind Inc.
- D3431
-
-